//
//  CellHeadeView.m
//  AmountBody
//
//  Created by smm on 2018/1/5.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

#import "CellHeadeView.h"

@implementation CellHeadeView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViews];
    }
    return self;
}
-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self setupViews];
    }
    return self;
}
-(void)setupViews
{
    _centerLabel = [[UILabel alloc]init];
    [self addSubview:_centerLabel];
    _leftImage = [[UIImageView alloc]init];
    [self addSubview:_leftImage];
    _rightImage = [[UIImageView alloc]init];
    [self addSubview:_rightImage];
    _nameLabel = [[UILabel alloc]init];
    [self addSubview:_nameLabel];
    
}


-(void)setCellHeadWithName:(NSString*)name
{
    _name = name;
    switch (_cellType) {
        case CellHeadTypeForNomal:
        {
            [self setCellHeadForNomal];
        }
            break;
        case CellHeadTypeForLittleTitle:
        {
            [self setCellHeadForLittleTitle];
        }
            break;
        case CellHeadTypeForVertical:
        {
            [self setCellHeadForVertical];
        }
            break;
        default:
            break;
    }
    
    
}

-(void)setCellHeadForNomal
{
    _nameLabel.hidden = YES;
    [self loadUI];
}
-(void)setCellHeadForLittleTitle//小标题
{
    _leftImage.hidden = YES;
    _rightImage.hidden = YES;
    _lineImage.hidden = YES;
    CGFloat jianGeW = 15;
    _nameLabel.hidden = NO;
    _nameLabel.text = _name;
    _nameLabel.font = Cell_Big_Font;
    _nameLabel.textColor = ZhongZi_Color;
//    [_nameLabel sizeToFit];
    [_nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(jianGeW);
        make.top.bottom.equalTo(self);
    }];
    
}

-(void)setCellHeadForVertical
{
    _nameLabel.hidden = YES;
    _leftImage.hidden = NO;
    _rightImage.hidden = YES;
    _leftImage.image = [UIImage imageNamed:@"shu_line"];
    _leftImage.contentMode = UIViewContentModeScaleAspectFit;
    _lineImage.hidden = YES;
    _centerLabel.text = _name;
    _centerLabel.font = [UIFont systemFontOfSize:16];
    _centerLabel.textColor = RGBColorAlpha(255, 66, 89, 1);
    [_centerLabel sizeToFit];
    CGFloat jianGeH = 15;
    
    [_leftImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(10);
        make.bottom.top.equalTo(self);
      
    }];
    
    [_centerLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-5);
        make.top.equalTo(self).offset(jianGeH);
        make.bottom.equalTo(self).offset(-jianGeH);
    }];
}

-(void)loadUI
{
    _centerLabel.hidden = NO;
    _leftImage.hidden = NO;
    _rightImage.hidden = NO;
    _lineImage.hidden = YES;
    _centerLabel.text = _name;
    _centerLabel.font = [UIFont systemFontOfSize:19];
    _centerLabel.textColor = ShenZi_Color;
    [_centerLabel sizeToFit];
    CGFloat jianGeH = 15;
    CGFloat imageW = 17;
    CGFloat imageH = 25;
    _leftImage.image = [UIImage imageNamed:@"@left"];
    [_leftImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@(imageW));
        make.right.equalTo(self.mas_centerX).offset(-(_centerLabel.frame.size.width/2.0+5));
        make.height.equalTo(@(imageH));
        make.top.equalTo(self).offset(jianGeH);
    }];
//    _leftImage.frame = CGRectMake((width-wid)/2.0, jianGeH, imageW, imageH);
    
    [_centerLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_leftImage.mas_right).offset(5);
        make.height.equalTo(@(30));
        make.top.equalTo(self).offset(jianGeH);
    }];
    [_rightImage mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_centerLabel.mas_right).offset(5);
        make.height.equalTo(@(imageH));
        make.width.equalTo(@(imageW));
        make.top.equalTo(self).offset(jianGeH);
    }];
    
    _rightImage.image = [UIImage imageNamed:@"@right"];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
